<?php
	class database
	{

		var $sql="";
		var $connection="";
		var $cursor=null;
		

		function database()
		{
			include('db.inc');
			if(empty($settings['dbpass']))
			{
				$settings['dbpass']='';
			}
			$this->connection =@mysql_connect($settings['hostname'],$settings['dbuser'],$settings['dbpass']);
			if(!$this->connection)
			{
				die("Error(1.1). Please configuration to again! <a href='install.php' style='color:blue' >Click here</a>");	
			}	
			
			if($settings['dbname']!="")
			{	
				if(!mysql_select_db($settings['dbname'],$this->connection))	
				{					
					$sql ="create database ".$settings["dbname"];
					$this->SetQuery($sql);
					$this->Query();
					if(!mysql_select_db($settings['dbname'],$this->connection))	
					{
						die("Error(1.2). database not exist! <a href='install.php' style='color:blue' >Click here</a>");
					}
				}
			}
		}		
		
		
		function SetQuery($sql)
		{
			$this->sql=$sql;
		}
		
		function Query()
		{
			mysql_query("set names 'utf8'");
			$this->cursor = mysql_query($this->sql,$this->connection);
			return $this->cursor;
		}
		function LoadAllRow()
		{
			if(!($cur=$this->query()))
			{
				return null;
			}
			$array=array();
			while($row=mysql_fetch_assoc($cur))
			{
				$array[]=$row;
			}
			mysql_free_result($cur);
			return $array;
		}
		function LoadOneRow()
		{
			if(!($cur=$this->query()))
			{
				return null;
			}
			$row=mysql_fetch_assoc($cur);
			mysql_free_result($cur);
			return $row;
		}
		function disconnect()
		{
			mysql_close($this->connection);
		}
	}
?>